function getCookie(c_name)
{
	if (document.cookie.length>0) {
		c_start=document.cookie.indexOf(c_name + "=")
		if (c_start !=-1) {
			c_start=c_start+c_name.length+1
			c_end=document.cookie.indexOf(";",c_start)
			if (c_end==-1) c_end=document.cookie.length
			return unescape(document.cookie.substring(c_start,c_end))
			}
		}
	return ""
}

function setCookie(c_name,value,expiredays) {
var exdate=new Date()
exdate.setDate(exdate.getDate()+expiredays)
document.cookie=c_name+ "=" + escape(value)+ ((expiredays==null) ? "" : ";expires="+exdate.toGMTString())
}

function checkCookie() {
	username=getCookie('username')
	if (username!=null && username != "" )
		{alert('Welcome '+username+'!') }
	else {
		username=prompt('Please enter your name:',"")
		if (username!=null && username !="")
		{ setCookie('username',username,365) }
    }
}

function cekLokasi() {
lokasi=getCookie('Lokasi');
	if (lokasi!=null && lokasi != "" )
		{
			
			}
	else {
		lokasi=prompt('Masukkan Lokasi:',"")
		if (lokasi!=null && lokasi !="")
		{ setCookie('Lokasi',lokasi,3365) }
    }
}


var c_valid='';
function CekPass(nm,psw) {
	if (nm.length==0 || psw.length==0) {
		alert("Masukkan ID dan Password");
		return false;
	}
	url="CekPass.php?usr=" + nm + "&passw=" + psw + "&sid=" + Math.random() ;
    xmlHttp=GetXmlHttpObject(stateChangedPass);
    xmlHttp.open("GET", url , false);
    xmlHttp.send(null)
		if (c_valid.length > 0 ) {
		   setCookie('username',c_valid,1);
		   return true;
		} else { 
			alert("user name atau password salah!");
			return false;
		}
	}

 function stateChangedPass()
{
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
    {	
		c_valid=xmlHttp.responseText;
    }
}
function GetXmlHttpObject(handler)
{
    var objXmlHttp=null
 
    if (navigator.userAgent.indexOf("Opera")>=0)
    {
        alert("Opera not supported...")
        return;
    }
    if (navigator.userAgent.indexOf("MSIE")>=0)
    {
        var strName="Msxml2.XMLHTTP"
        if (navigator.appVersion.indexOf("MSIE 5.5")>=0)
        {
            strName="Microsoft.XMLHTTP"
        }
        try
        {
            objXmlHttp=new ActiveXObject(strName)
            objXmlHttp.onreadystatechange=handler
            return objXmlHttp
        }
        catch(e)
        {
            alert("Error. Scripting for ActiveX might be disabled")
            return
        }
    }
    if (navigator.userAgent.indexOf("Mozilla")>=0)
    {
        objXmlHttp=new XMLHttpRequest()
        objXmlHttp.onload=handler
        objXmlHttp.onerror=handler
        return objXmlHttp
    }
} 